import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../view/RadiusBorder.dart';
import 'logic.dart';

class HousePage extends StatelessWidget {
  final logic = Get.put(HouseLogic());
  final state = Get.find<HouseLogic>().state;

  HousePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      buildSearch(context),
      BrnTabBar(
        tabs: state.tabList,
        controller: logic.tabController,
        labelColor: Colors.green,
        unselectedLabelColor: Colors.grey,
        indicatorColor: Colors.green,
        indicatorWidth: 20.w,
        indicatorWeight: 3.h,
        isScroll: false,
        onTap: (state, index) => {logic.changTab(index)},
      ),
      Expanded(
          child: PageView.builder(
              controller: logic.pageController,
              onPageChanged: logic.changPage,
              itemCount: state.tabList.length,
              itemBuilder: (context, index) {
                return Column(children: [
                  BrnSelectionView(
                      originalSelectionData:
                          logic.selectionData?.list ?? List.empty(),
                      onSelectionPreShow:
                          (int index, BrnSelectionEntity entity) {
                        return entity.filterShowType ??
                            BrnSelectionWindowType.list;
                      },
                      onSelectionChanged: (int menuIndex,
                          Map<String, String> filterParams,
                          Map<String, String> customParams,
                          BrnSetCustomSelectionMenuTitle
                              setCustomTitleFunction) {
                        BrnToast.show(filterParams.toString(), context);
                      }),
                  GetBuilder<HouseLogic>(builder: (builder) {
                    return ListView.builder(
                        itemCount: logic.houseList?.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Text(logic.houseList?[index].address ?? "");
                        });
                  })
                ]);
              })),
    ]);
  }

  Widget buildSearch(BuildContext context) {
    return Padding(
        padding: EdgeInsets.only(bottom: 1.h),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            RadiusSearchBorder(
              radius: 5.r,
              borderColor: Colors.black12,
              searchWidth: 0.80.sw,
              searchHeight: 30.h,
              onTap: () =>
                  BrnToast.showInCenter(text: "跳转到搜索页面", context: context),
            ),
            Padding(
                padding: EdgeInsets.only(
                    top: ScreenUtil().statusBarHeight + 10.h, right: 18.w),
                child: InkWell(
                    child: Image.asset(state.addIcon, width: 22, height: 22),
                    onTap: () => BrnToast.showInCenter(
                        text: "跳转到新增房源页面", context: context)))
          ],
        ));
  }
}
